/*  
* Copyright 2013-2020 Smartdot Technologies Co., Ltd. All rights reserved.  * SMARTDOT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.  * 
*/ package com.ssm.zhou.web;

import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.zhou.dto.LoginRespDto;
import com.ssm.zhou.dto.LoginUserDto;
import com.ssm.zhou.dto.enums.LoginRespEnum;
import com.ssm.zhou.service.IUserService;
import com.ssm.zhou.service.impl.UserServiceImpl;

/** 
 * <p>  
 *   
 * @author <a href="mailto:zhoujb@smartdot.com.cn">周竞博</a>  * @version 1.0, 2020年5月30日 
 */
@Controller
@RequestMapping(value="/login")
public class LoginController {
	@Autowired
	private IUserService userService;
	private static Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME); 
	
	@RequestMapping(value="/submit",method = RequestMethod.POST,produces="application/json;charset=UTF-8")
	@ResponseBody
	public LoginRespDto handlerLogin(@RequestBody LoginUserDto loginUserDto,HttpSession httpSession){
		LoginRespDto loginResp = null;
		try {

			logger.debug(loginUserDto);
			logger.debug("进入登录Controller");
			logger.debug(userService.userLogin(loginUserDto));
			loginResp = userService.userLogin(loginUserDto);
			// 如果验证正确，然后把数据库返回的用户信息存到session
			if(loginResp.getRespCode().equals("0")){
				httpSession.setAttribute("userInfo", loginResp.getLoginRespUser());
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return loginResp;

	}
}
 